//
//  OrderEntity.m
//  SXH
//
//  Created by Jack on 15/9/8.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "OrderEntity.h"
#import "OrderProductEntity.h"

@implementation OrderEntity

@synthesize ID,insert_time,order_num,total_amount,status,ship_cost,order_class,store_id,store_name;
@synthesize product_list;

- (instancetype)initWithAttributes:(NSDictionary *)attributes {
    
    self = [super init];
    if (!self) {
        return nil;
    }
    
    self.ID= [NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"id"]];
    self.insert_time = [attributes valueForKeyPath:@"insert_time"];
    self.order_num = [attributes valueForKeyPath:@"order_num"];
    self.total_amount = [NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"total_amount"]];
    self.status = [NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"status"]];
    self.ship_cost = [NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"ship_cost"]];
    self.order_class = [NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"order_class"]];
    self.store_id = ([attributes valueForKeyPath:@"order_class"]==[NSNull null])?@"NULL":[NSString stringWithFormat:@"%@",[attributes valueForKeyPath:@"order_class"]];
    self.store_name = ([attributes valueForKeyPath:@"store_name"]==[NSNull null])?@"NULL":[attributes valueForKeyPath:@"store_name"];
    self.payWay = ([attributes valueForKeyPath:@"payWay"]==[NSNull null])?@"NULL":[attributes valueForKeyPath:@"payWay"];
    self.can_cancel = [attributes valueForKeyPath:@"can_cancel"];
    
    NSArray *array  = [attributes valueForKeyPath:@"product_list"];
    product_list = [[NSMutableArray alloc] init];
    
    for (NSDictionary* attributes in array) {
        OrderProductEntity *entity = [[OrderProductEntity alloc] init];
        entity = [entity initWithAttributes:attributes];
        [product_list addObject:entity];
    }
    
    return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder{
    //    [encoder encodeObject:self forKey:@"orderEntity"];
    [encoder encodeObject:self.ID forKey:@"ID"];
    [encoder encodeObject:self.insert_time forKey:@"insert_time"];
    [encoder encodeObject:self.order_num forKey:@"order_num"];
    [encoder encodeObject:self.total_amount forKey:@"total_amount"];
    [encoder encodeObject:self.status forKey:@"status"];
    [encoder encodeObject:self.ship_cost forKey:@"ship_cost"];
    [encoder encodeObject:self.store_id forKey:@"store_id"];
    [encoder encodeObject:self.store_name forKey:@"store_name"];
    [encoder encodeObject:self.product_list forKey:@"product_list"];
    [encoder encodeObject:self.payWay forKey:@"payWay"];
    [encoder encodeObject:self.order_class forKey:@"order_class"];
    [encoder encodeObject:self.can_comment forKey:@"can_comment"];
    [encoder encodeObject:self.can_cancel forKey:@"can_cancel"];
}

- (id)initWithCoder:(NSCoder *)decoder{
    if(self = [super init]) {
        //        self = [decoder decodeObjectForKey:@"orderEntity"];
        self.ID = [decoder decodeObjectForKey:@"ID"];
        self.insert_time = [decoder decodeObjectForKey:@"insert_time"];
        self.order_num = [decoder decodeObjectForKey:@"order_num"];
        self.total_amount = [decoder decodeObjectForKey:@"total_amount"];
        self.status = [decoder decodeObjectForKey:@"status"];
        self.ship_cost = [decoder decodeObjectForKey:@"ship_cost"];
        self.store_id = [decoder decodeObjectForKey:@"store_id"];
        self.store_name = [decoder decodeObjectForKey:@"store_name"];
        self.product_list = [decoder decodeObjectForKey:@"product_list"];
        self.payWay = [decoder decodeObjectForKey:@"payWay"];
        self.order_class = [decoder decodeObjectForKey:@"order_class"];
        self.can_comment = [decoder decodeObjectForKey:@"can_comment"];
        self.can_cancel = [decoder decodeObjectForKey:@"can_cancel"];

    }
    return self;
}

@end
